﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;
using NickLee.Common;
namespace GPCSC.Web.sjsbyes
{
    public partial class myMQEdit : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Usual.f_querystringToString("command") != "" && (Usual.f_querystringToString("command") != null))
                {
                    this.MtxtD_tabid.Value = Usual.f_querystringToString("newsid");

                    if (Usual.f_querystringToString("command") == "view")//查看
                    {
                        Button1.Style.Add("display", "none");
                        Button2.Style.Add("display", "none");
                        type.Value = "view";
                    }
                    else//修改
                    {

                    }
                    //DD1.Visible = false;
                    //DD2.Visible = false;
                    f_fristLoad(this.MtxtD_tabid.Value);
                }
                else
                {
                    this.MtxtD_tabid.Value = Guid.NewGuid().ToString();
                    //builddd1();
                    //builddd2();
                    //this.MtxtD_lgname.Style.Add("display", "none");
                    //this.tes1.Style.Add("display", "none");

                }
            }
        }
        protected void f_fristLoad(string PrimaryKey)
        {
            base.o_uiTable.Clear();
            SqlReadXml org = new SqlReadXml();
            base.o_uiTable.Add("@tabids", PrimaryKey);
            base.m_uiDataSet = org.ReaderDataSet("sel_mqrj_ones", base.o_uiTable);
            if (base.m_uiDataSet.Tables.Count > 0)
            {
                if (base.m_uiDataSet.Tables[0].Rows.Count > 0)
                {
                    //UIFactory set UI controls value:界面工厂设置界面控件值
                    try
                    {
                        base.m_uiDataSet.Tables[0].Rows[0]["mqrj"]=  base.m_uiDataSet.Tables[0].Rows[0]["mqrj"].ToString().Replace("^","\n");
                        base.o_uiTable = UIFactory.UIFactory_Set(this, base.m_uiDataSet.Tables[0]);

                    }
                    catch
                    {

                    }
                    //this.tes1.Value = base.m_uiDataSet.Tables[0].Rows[0]["hdtitile"].ToString();
                    //your can do databind yourself:对界面工厂不能填充的数据，通过ODRM手动填充
                }
            }
        }
        //protected void builddd1()//绑定活动
        //{
        //    Hashtable htable = new Hashtable();
        //    DataSet ds = new DataReturn().ReturnData(htable, "sel_hdlist_all");
        //    this.MtxtD_hdid.Value = ds.Tables[0].Rows[0]["hdsid"].ToString();
        //    DD1.DataSource = ds;
        //    DD1.DataBind();
        //}
        //protected void builddd2()//绑定人员
        //{
        //    Hashtable htable = new Hashtable();
        //    DataSet ds = new DataReturn().ReturnData(htable, "sel_user_all");
        //    this.MtxtD_lgid.Value = ds.Tables[0].Rows[0]["CL_USER_SOID"].ToString();
        //    this.MtxtD_lgname.Value = ds.Tables[0].Rows[0]["USERNAME"].ToString();
        //    DD2.DataSource = ds;
        //    DD2.DataBind();
        //}
        protected void editnews()//修改
        {
            try
            {
                base.o_uiTable.Clear();
                this.MtxtD_mqrj.Value = this.MtxtD_mqrj.Value.Replace("\n", "^");
                base.o_uiTable = UIFactory.UIFactory_Get(this);
                SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();

                dtable.databyhtables(base.o_uiTable, "update", "FK_MQ", "tabid", this.MtxtD_tabid.Value);
                this.Response.Write("<script>alert('修改成功！');window.location.href='MYMQ.aspx';</script>");
            }
            catch 
            {
                base.o_uiTable.Clear();
                this.MtxtD_mqrj.Value = new NotHTML().NoHTML(this.MtxtD_mqrj.Value);
                base.o_uiTable = UIFactory.UIFactory_Get(this);
                SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();

                dtable.databyhtables(base.o_uiTable, "update", "FK_MQ", "tabid", this.MtxtD_tabid.Value);
                this.Response.Write("<script>alert('修改成功！');window.location.href='MYMQ.aspx';</script>");
            }
        }


        protected void Button1_Click(object sender, EventArgs e)
        {
            if (MtxtD_mqrj.Value.Trim() == "")
            {
                Response.Write("<script>alert('内容不能为空');</script>");
            }
            else
            {
                if (Usual.f_querystringToString("command") != "" && Usual.f_querystringToString("command") != null)
                {
                    editnews();
                }
                else
                {
                    saveNews();
                }
            }
        }
        /// <summary>
        /// 保存新闻
        /// </summary>
        protected void saveNews()
        {
            try
            {
                if (MtxtD_mqrj.Value.Trim() == "")
                {
                    Response.Write("<script>alert('内容不能为空');</script>");
                }
                else
                {
                    base.o_uiTable.Clear();
                    this.MtxtD_mqrj.Value = this.MtxtD_mqrj.Value.Replace("\n", "^");
                    //this.MtxtD_mqrj.Value = new NotHTML().NoHTML(this.MtxtD_mqrj.Value);
                    base.o_uiTable = UIFactory.UIFactory_Get(this);

                    byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
                    Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
                    Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];

                    base.o_uiTable.Add("lgid", users.CL_USER_SOID.ToString());

                    base.o_uiTable.Add("lgname", users.REALNAME.ToString());

                    SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                    dtable.databyhtables(base.o_uiTable, "add", "FK_MQ", "", "");

                    this.Response.Write("<script>alert('添加成功！');window.location.href='MYMQ.aspx';</script>");
                }
            }
            catch 
            {
               if (MtxtD_mqrj.Value.Trim() == "")
                {
                    Response.Write("<script>alert('内容不能为空');</script>");
                }
                else
                {
                    base.o_uiTable.Clear();
                    //this.MtxtD_mqrj.Value = this.MtxtD_mqrj.Value.Replace("\n", "^");
                   this.MtxtD_mqrj.Value = new NotHTML().NoHTML(this.MtxtD_mqrj.Value);
                    base.o_uiTable = UIFactory.UIFactory_Get(this);

                    byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
                    Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
                    Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];

                    base.o_uiTable.Add("lgid", users.CL_USER_SOID.ToString());

                    base.o_uiTable.Add("lgname", users.REALNAME.ToString());

                    SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                    dtable.databyhtables(base.o_uiTable, "add", "FK_MQ", "", "");

                    this.Response.Write("<script>alert('添加成功！');window.location.href='MYMQ.aspx';</script>");
                }
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (Usual.f_querystringToString("command") != "" && Usual.f_querystringToString("command") != null)
            {
                editnewss();
            }
            else
            {
                saveNewss();
            }
        }

        /// <summary>
        /// 保存新闻
        /// </summary>
        protected void saveNewss()
        {
            try
            {
                if (MtxtD_mqrj.Value.Trim() == "")
                {
                    Response.Write("<script>alert('内容不能为空');</script>");
                }
                else
                {
                    base.o_uiTable.Clear();
                    this.MtxtD_mqrj.Value = this.MtxtD_mqrj.Value.Replace("\n", "^");
                    base.o_uiTable = UIFactory.UIFactory_Get(this);

                    byte[] userInfo = (byte[])base.o_baseTable[c_obj.s_userInfo];
                    Hashtable userInfoTable = CompressData.UnCompressHashtable(userInfo);
                    Model.CL_USER_S users = (Model.CL_USER_S)userInfoTable["SYS_USER"];

                    base.o_uiTable.Add("lgid", users.CL_USER_SOID.ToString());

                    base.o_uiTable.Add("lgname", users.REALNAME.ToString());
                    base.o_uiTable.Add("isBs", 1);

                    SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                    dtable.databyhtables(base.o_uiTable, "add", "FK_MQ", "", "");

                    this.Response.Write("<script>alert('添加成功！');window.location.href='MYMQ.aspx';</script>");
                }
            }
            catch (Exception ee)
            {
                throw ee;
            }
        }

        protected void editnewss()//修改
        {
            try
            {
                base.o_uiTable.Clear();
                this.MtxtD_mqrj.Value = this.MtxtD_mqrj.Value.Replace("\n", "^");
                base.o_uiTable = UIFactory.UIFactory_Get(this);
                SQLServerDAL.databyhtable dtable = new SQLServerDAL.databyhtable();
                base.o_uiTable.Add("isBs", 1);
                dtable.databyhtables(base.o_uiTable, "update", "FK_MQ", "tabid", this.MtxtD_tabid.Value);
                this.Response.Write("<script>alert('修改成功！');window.location.href='MYMQ.aspx';</script>");
            }
            catch (Exception ee)
            {
                throw ee;
            }
        }
    }
}